﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.DO;
using VINETLIFE.BL;
using Telerik.Web.UI;
using Telerik.Web.UI.Editor.DialogControls;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Drawing.Drawing2D;
using System.Data;

namespace VINETLIFE.AdminCP
{
    public partial class Product : System.Web.UI.Page
    {
        cmsProductDO objProduct = new cmsProductDO();
        List<cmsProductLocationDO> lstProLoc = new List<cmsProductLocationDO>();
        List<string> lstX = new List<string>();
        protected void Page_Load(object sender, EventArgs e)
        {
            //LoadListProperty();
            if (!string.IsNullOrEmpty(Request.QueryString["ProductID"]))
            {
                TabPanelColor.Visible = true;
                divProductColor.Visible = true;
                ltrAction.Text = "Cập nhật sản phẩm";
                int productID = int.Parse(Request.QueryString["ProductID"]);
                objProduct.ProductID = productID;
                if (!IsPostBack)
                {
                    ddlHour.Items.Add(new ListItem("Hãy chọn", "-1"));
                    for (int id = 0; id <= 23; id++)
                    {
                        ddlHour.Items.Add(new ListItem(id.ToString() + "h", id.ToString()));
                    }
                    ddlMin.Items.Add(new ListItem("Hãy chọn", "-1"));
                    for (int id = 0; id <= 59; id++)
                    {
                        ddlMin.Items.Add(new ListItem(id.ToString() + "p", id.ToString()));
                    }
                   // Functions.ddlDatabinder(ddlParentCate, cmsProductCategoryDO.PRODUCTCATEGORYID_FIELD, cmsProductCategoryDO.PRODUCTCATEGORYTITLE_FIELD, new cmsProductCategoryBL().SelectAll());
                    Functions.bindToDropDown(ddlParentCate, new cmsProductCategoryBL().SelectAll(), "ParentID", "ProductCategoryID", "ProductCategoryTitle");
                    Functions.ddlDatabinder(ddlOrigin, cmsOriginDO.ORIGINID_FIELD, cmsOriginDO.ORIGIN_FIELD, new cmsOriginBL().SelectAll());
                    InitForm();
                    ddlProductLocationDataSource();
                    LoadProductColor();
                    int productCategoryID = int.Parse(dropCate.SelectedValue);
                    if (productCategoryID >= 0)
                    {
                        //rptListProperties.DataSource = new cmsProductPropertyBL().SelectByProductIDAndCate(productCategoryID, productCategoryID);
                        rptListProperties.DataSource = new cmsPropertiesBL().SelectByProductCategory(productCategoryID);
                        rptListProperties.DataBind();
                    }
                }
            }
            else
            {
                TabPanelColor.Visible = false;
                divProductColor.Visible = false;
                ltrAction.Text = "Thêm mới sản phẩm";
                if (!IsPostBack)
                {
                    ddlProductLocationDataSource();
                    ddlHour.Items.Add(new ListItem("Hãy chọn", "-1"));
                    for (int id = 0; id <= 23; id++)
                    {
                        ddlHour.Items.Add(new ListItem(id.ToString() + "h", id.ToString()));
                    }
                    ddlMin.Items.Add(new ListItem("Hãy chọn", "-1"));
                    for (int id = 0; id <= 59; id++)
                    {
                        ddlMin.Items.Add(new ListItem(id.ToString() + "p", id.ToString()));
                    }
                    Functions.bindToDropDown(ddlParentCate, new cmsProductCategoryBL().SelectAll(), "ParentID", "ProductCategoryID", "ProductCategoryTitle");
                    Functions.ddlDatabinder(ddlOrigin, cmsOriginDO.ORIGINID_FIELD, cmsOriginDO.ORIGIN_FIELD, new cmsOriginBL().SelectAll());
                }
            }
        }
        protected void ddlProductLocationDataSource()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ProductId"]))
            {
                lstProLoc = new cmsProductLocationBL().SelectListByProductCode(objProduct.ProductCode);
                if (lstProLoc.Count > 0)
                {
                    foreach (var item in lstProLoc)
                    {
                        lstX.Add(item.LocationCode);
                    }
                }
            }
            ddlProductLocation.DataSource = new cmsLocationBL().SelectAll();
            ddlProductLocation.DataBind();
        }
        protected void InitForm()
        {
            objProduct = new cmsProductBL().Select(objProduct);

            txtHomeDescription.Text = objProduct.HomeDescription;
            txtFDescription.Text = objProduct.Description;
            txtMoTaChiTiet.Text = objProduct.DetailDescription;
            txtProductCode.Text = objProduct.ProductCode;
            txtProductTitle.Text = objProduct.ProductTitle;
            txtOrderID.Text = objProduct.OrderID.ToString();
            txtWarranty.Text = objProduct.Warranty;
            cbIsNew.Checked = objProduct.IsNew;
            cbIsBestBuy.Checked = objProduct.IsNew;
            txtPrice.Text = objProduct.Price.ToString();
            txtSalePrice.Text = objProduct.SalePrice.ToString();
            cboIsSetTop.Checked = objProduct.IsSetTop;
            cboIsPromotion.Checked = objProduct.IsPromotion;
            cboIsHomePage.Checked = objProduct.IsHomepage;
            cboIsFinished.Checked = objProduct.IsFinished;
            txtProvider.Text = objProduct.Provider;
            txtTermOfUse.Text = objProduct.TermOfUse;
            txtMemberPrice.Text = objProduct.MemberPrice.ToString();
            //SEO
            txtMetaDes.Text = objProduct.MetaDes;
            txtMetaTag.Text = objProduct.MetaTag;
            txtpagsTitle.Text = objProduct.PageTitle;
            //
            if (objProduct.Active == true) rdActive.Checked = true;
            else RadioButton1.Checked = true;
            if (!string.IsNullOrEmpty(objProduct.ProductImage))
            {
                hplImage.Visible = true;

                hplImage.NavigateUrl = "/Media/" + objProduct.ProductImage;

            }
            if (!string.IsNullOrEmpty(objProduct.PromotionImages))
            {
                hplImages.Visible = true;
                hplImages.NavigateUrl = "/Media/" + objProduct.PromotionImages;
            }
            if (!string.IsNullOrEmpty(objProduct.ChartImage))
            {
                hplChartImage.Visible = false;
                hplChartImages.Visible = false;
                hplChartImage.NavigateUrl = "/Media/" + objProduct.ChartImage;
                hplChartImages.NavigateUrl = "/Media/" + objProduct.ChartImage;
            }
            try
            {
                ddlParentCate.SelectedValue = objProduct.ProductCategoryID.ToString();
                ddlOrigin.SelectedValue = objProduct.OriginID.ToString();
                //time
                if ((objProduct.PromotionEndDate > new DateTime(1950, 01, 01)))
                {
                    ddlHour.SelectedValue = objProduct.PromotionEndDate.Hour.ToString();
                    ddlMin.SelectedValue = objProduct.PromotionEndDate.Minute.ToString();
                    dtNgayXB.SelectedDate = objProduct.PromotionEndDate.Date;
                }
            }
            catch
            {
            }
        }
        protected void SetProject()
        {
            objProduct = new cmsProductBL().Select(objProduct);
            objProduct.IsNew = cbIsNew.Checked;
            objProduct.IsBestbuy = cbIsBestBuy.Checked;
            if (rdActive.Checked == true) objProduct.Active = true;
            else objProduct.Active = false;
            objProduct.OrderID = int.Parse(txtOrderID.Text.Trim());
            objProduct.ProductCode = txtProductCode.Text.Trim();
            objProduct.ProductTitle = txtProductTitle.Text.Trim();
            objProduct.Description = txtFDescription.Text.Trim();
            objProduct.DetailDescription = txtMoTaChiTiet.Text;
            objProduct.HomeDescription = txtHomeDescription.Text;
            objProduct.Price = long.Parse(txtPrice.Text);
            objProduct.Provider = txtProvider.Text;
            objProduct.TermOfUse = txtTermOfUse.Text;
            objProduct.MemberPrice = long.Parse(txtMemberPrice.Text);
            //promotion
            objProduct.IsPromotion = cboIsPromotion.Checked;
            objProduct.IsSetTop = cboIsSetTop.Checked;
            objProduct.IsHomepage = cboIsHomePage.Checked;
            objProduct.IsFinished = cboIsFinished.Checked;
            objProduct.SalePrice = long.Parse(txtSalePrice.Text.Trim());
            objProduct.MetaDes = txtMetaDes.Text.Trim();
            objProduct.MetaTag = txtMetaTag.Text.Trim();
            objProduct.PageTitle = txtpagsTitle.Text.Trim();
            objProduct.Warranty = txtWarranty.Text.Trim();


            //objProduct.PromotionEndDate = 

            if (cboIsPromotion.Checked)
            {
                if (dtNgayXB.SelectedDate != null)
                {
                    int hour = 0;
                    int minute = 0;
                    if(int.Parse(ddlHour.SelectedValue)!=-1)
                        hour =int.Parse(ddlHour.SelectedValue);
                    if (int.Parse(ddlMin.SelectedValue) != -1)
                        minute = int.Parse(ddlMin.SelectedValue);
                    DateTime dt = Convert.ToDateTime(dtNgayXB.SelectedDate);
                    objProduct.PromotionEndDate = new DateTime(dt.Year, dt.Month, dt.Day, hour, minute, 0);
                }
                else
                {
                    objProduct.PromotionEndDate = new DateTime(1753, 1, 1);
                }
            }
            else
            {
                objProduct.PromotionEndDate = new DateTime(1753, 1, 1);
            }
            if (!string.IsNullOrEmpty(fulImage.FileName))
            {

                objProduct.ProductImage = UploadFile(fulImage, "pttd", txtProductTitle.Text);
            }
            if (!string.IsNullOrEmpty(fuAnhBanVe.FileName))
            {

                objProduct.ChartImage = UploadFile(fuAnhBanVe, "chart", txtProductTitle.Text);
            }
            objProduct.ProductCategoryID = int.Parse(ddlParentCate.SelectedValue);
            objProduct.OriginID = int.Parse(ddlOrigin.SelectedValue);
            if (!string.IsNullOrEmpty(fulImages.FileName))
                objProduct.PromotionImages = UploadFileKM(fulImages);
        }

        private string UploadFileKM(FileUpload fulImages)
        {
            if (!string.IsNullOrEmpty(fulImages.FileName))
            {
                string FileName = string.Format("{0}{1}", Functions.Change_AV(txtProductTitle.Text) + "-" + DateTime.Now.ToString("ddMMyyyyhhmmss"), fulImages.FileName.Substring(fulImages.FileName.LastIndexOf(".")));
                string SaveLocation = string.Format("{0}\\{1}", Server.MapPath("~/Media/"), FileName);
                fulImages.SaveAs(SaveLocation);
                return FileName;
            }
            return string.Empty;
        }

        private string UploadFile(FileUpload fulImage, string s, string text)
        {
            if (!string.IsNullOrEmpty(fulImage.FileName))
            {

                string FileName = string.Format("{0}{1}", Functions.Change_AV(txtProductTitle.Text) + "-" + DateTime.Now.ToString("ddMMyyyyhhmmss"), fulImage.FileName.Substring(fulImage.FileName.LastIndexOf(".")));
                string preName = Functions.Change_AV(txtProductTitle.Text) + "-" + DateTime.Now.ToString("ddMMyyyyhhmmss");
                string typeName = fulImage.FileName.Substring(fulImage.FileName.LastIndexOf("."));

                string SaveLocation = string.Format("{0}\\{1}", Server.MapPath("~/Media/"), FileName);
                fulImage.SaveAs(SaveLocation);

                objProduct.Thumbnail = preName + "_thumbnail" + typeName;

                string pathAvatars = Server.MapPath("~/Media/thumbnail/");
                try
                {
                    int thumbWidth = 400;
                    int thumbHeight = 300;
                    System.Drawing.Image oImg = System.Drawing.Image.FromStream(fulImage.PostedFile.InputStream);
                    System.Drawing.Image oThumbNail = new Bitmap(thumbWidth, thumbHeight, oImg.PixelFormat);
                    Graphics oGraphic = Graphics.FromImage(oThumbNail);
                    oGraphic.CompositingQuality = CompositingQuality.HighQuality;
                    oGraphic.SmoothingMode = SmoothingMode.HighQuality;
                    oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    Rectangle oRectangle = new Rectangle(0, 0, thumbWidth, thumbHeight);
                    oGraphic.DrawImage(oImg, oRectangle);
                    oThumbNail.Save(pathAvatars + objProduct.Thumbnail, ImageFormat.Jpeg);
                    oImg.Dispose();
                }
                catch (Exception ex)
                {
                    Response.Write("Error: " + ex.Message);
                }

                return FileName;
            }
            return string.Empty;
        }
        protected void ddlParentCate_SelectedIndexChanged(object sender, EventArgs e)
        {
            int productCategoryID = int.Parse(ddlParentCate.SelectedValue);
            if (productCategoryID > 0)
            {
                //rptListProperties.DataSource = new cmsPropertiesBL().SelectByProductCategory(productCategoryID);

            }
        }

        protected void dropCate_SelectedIndexChanged(object sender, EventArgs e)
        {
            int productCategoryID = int.Parse(dropCate.SelectedValue);
            if (productCategoryID >= 0)
            {
                rptListProperties.DataSource = new cmsPropertiesBL().SelectByProductCategory(productCategoryID);
                rptListProperties.DataBind();
            }
        }

        void LoadListProperty()
        {
            rptListProperties.DataSource = new cmsPropertiesBL().SelectAll();
            rptListProperties.DataBind();
        }
        protected void rptListProperties_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {
            Label lblproductPropertyID = (Label)e.Item.FindControl("lblID");
            Label ltID = (Label)e.Item.FindControl("lblPropertyID");
            Label ltName = (Label)e.Item.FindControl("lblPropertyName");
            Label ltValue = (Label)e.Item.FindControl("lblValue");
            TextBox txtValue1 = (TextBox)e.Item.FindControl("txtValue");
            cmsPropertiesDO itemDO = new cmsPropertiesBL().Select(new cmsPropertiesDO() { PropertyID = int.Parse(ltID.Text) });
            if (itemDO.ParentID == 0)
            {
                txtValue1.Visible = true;
                ltValue.Visible = false;
                ltValue.Text = " (Thuộc tính cha)";
                ltName.CssClass = "text";

            }
            else
            {
                ltName.CssClass = "text-padding";
            }
            cmsProductPropertyDO objProPer = new cmsProductPropertyDO();
            cmsProductPropertyBL proPerBL = new cmsProductPropertyBL();
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["ProductID"]))
                {
                    int productID = int.Parse(Request.QueryString["ProductID"]);
                    int propertyID = int.Parse(((Label)e.Item.FindControl("lblPropertyID")).Text);
                    objProPer.ProductID = productID;
                    objProPer.PropertyID = propertyID;

                    proPerBL.SelectByFK(objProPer);
                    TextBox txtValue = (TextBox)e.Item.FindControl("txtValue");
                    txtValue.Text = objProPer.Value;
                    lblproductPropertyID.Text = objProPer.ProductPropertyID.ToString();
                }
            }
        }
        public string FreindlyUrl(string s)
        {
            return Functions.Change_AV(s);
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("ListProduct.aspx");
        }

        public bool Validate()
        {
            if (ddlParentCate.SelectedValue == "0")
            {
               
                return false;
            }
            else
                return true;
        }

        protected void btnLuu_Click(object sender, EventArgs e)
        {
            cmsProductPropertyDO objProPer = new cmsProductPropertyDO();
            cmsProductPropertyBL proPerBL = new cmsProductPropertyBL();
            /// objProPer.ProductPropertyID > 0  -> ;
            if (Validate())
            {
                if (objProduct.ProductID <= 0)
                {
                    SetProject();
                    int productID = new cmsProductBL().Insert(objProduct);
                    foreach (RepeaterItem item in rptListProperties.Items)
                    {
                        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                        {

                            TextBox txtValue = (TextBox)item.FindControl("txtValue");
                            Label lblPropertyID = (Label)item.FindControl("lblPropertyID");
                            objProPer.ProductID = productID;
                            objProPer.PropertyID = int.Parse(lblPropertyID.Text);
                            cmsPropertiesDO itemDO = new cmsPropertiesBL().Select(new cmsPropertiesDO() { PropertyID = int.Parse(lblPropertyID.Text) });
                            if (!txtValue.Text.Trim().Equals(""))
                            {
                                objProPer.Value = txtValue.Text.Trim();
                                proPerBL.Insert(objProPer);
                            }
                        }
                    }

                    ///new cmsProductLocationBL().DeleteByProductCode(objProduct.ProductCode);
                    cmsProductLocationDO objProLoc = new cmsProductLocationDO();
                    int dem = 0;
                    foreach (var item in ddlProductLocation.CheckedItems)
                    {
                        objProLoc.ProductCode = objProduct.ProductCode;
                        objProLoc.LocationCode = item.Value;
                        objProLoc.OrderId = dem;

                        new cmsProductLocationBL().Insert(objProLoc);
                        dem++;
                    }

                    //  Functions.Alert("Thêm bản ghi thành công", "ListProduct.aspx?Pid=" + ddlParentCate.SelectedValue);
                    Functions.Alert("Thêm bản ghi thành công", "Product.aspx?ProductID=" + productID);
                }
                else
                {
                    int productID = int.Parse(Request.QueryString["ProductID"]);
                    int productCategoryID = int.Parse(ddlParentCate.SelectedValue);
                    SetProject();

                    new cmsProductLocationBL().DeleteByProductCode(objProduct.ProductCode);
                    cmsProductLocationDO objProLoc = new cmsProductLocationDO();

                    int dem = 0;
                    foreach (var item in ddlProductLocation.CheckedItems)
                    {
                        objProLoc.ProductCode = objProduct.ProductCode;
                        objProLoc.LocationCode = item.Value;
                        objProLoc.OrderId = dem;

                        new cmsProductLocationBL().Insert(objProLoc);
                        dem++;
                    }

                    // Trường hợp chọn Danh mục khác => Xóa toàn bộ thuộc tính của danh mục cũ sau đó Insert mới
                    if (objProduct.ProductCategoryID != productCategoryID)
                    {
                        new cmsProductBL().Update(objProduct);
                        // new cmsProductPropertyBL().DeleteByProductID(productID);
                        foreach (RepeaterItem item in rptListProperties.Items)
                        {
                            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                            {
                                Label lblID = (Label)item.FindControl("lblID");
                                TextBox txtValue = (TextBox)item.FindControl("txtValue");
                                Label lblPropertyID = (Label)item.FindControl("lblPropertyID");
                                int productPropertyID = int.Parse(lblID.Text);
                                objProPer.ProductID = productID;
                                objProPer.PropertyID = int.Parse(lblPropertyID.Text);
                                if (productPropertyID <= 0)
                                {
                                    if (!txtValue.Text.Trim().Equals(""))
                                    {
                                        objProPer.Value = txtValue.Text.Trim();
                                        proPerBL.Insert(objProPer);
                                    }
                                }
                                else
                                {
                                    proPerBL.Update(objProPer);
                                }

                            }
                        }
                        // Functions.Alert("Cập nhật dữ liệu thành công", "ListProduct.aspx?Pid=" + ddlParentCate.SelectedValue);
                        Functions.Alert("Cập nhật dữ liệu thành công", "Product.aspx?ProductID=" + objProduct.ProductID);
                    }
                    //Trường hợp ko đổi danh mục(ko đổi thuộc tính) => Kiểm tra xem là Update hay insert thuộc tính....
                    else
                    {
                        SetProject();
                        new cmsProductBL().Update(objProduct);
                        foreach (RepeaterItem item in rptListProperties.Items)
                        {
                            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                            {
                                TextBox txtValue = (TextBox)item.FindControl("txtValue");
                                Label lblPropertyID = (Label)item.FindControl("lblPropertyID");
                                objProPer.ProductID = productID;
                                objProPer.PropertyID = int.Parse(lblPropertyID.Text);
                                objProPer.Value = txtValue.Text.Trim();

                                proPerBL.UpdateOrInsert(objProPer);
                            }
                        }
                        //  Functions.Alert("Cập nhật dữ liệu thành công", "ListProduct.aspx?Pid=" + ddlParentCate.SelectedValue);
                        Functions.Alert("Cập nhật dữ liệu thành công", "Product.aspx?ProductID=" + objProduct.ProductID);
                    }

                }
            }
            else
            {
                Functions.Alert("Nhập danh mục sản phẩm");
                return;
            }
            Ultility.ClearAllCache();
        }
        //color
        public string Color(object e)
        {
            string color = "";
            try
            {
                int productColorID = int.Parse(e.ToString());
                ProductColorDO objColor = new ProductColorBL().Select(new ProductColorDO() { ProductColorID = productColorID });
                color = "<span class='colorx' style='background:" + objColor.Color + "'></span>";
            }
            catch (Exception)
            {

                throw;
            }
            return color;
        }
        protected void LoadProductColor()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ProductID"]))
            {
                int productID = int.Parse(Request.QueryString["ProductID"]);
                gvProductColor.DataSource = new ProductColorBL().GetByProduct(productID);
                gvProductColor.DataBind();
            }
        }
        protected void gvProductColor_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvProductColor.PageIndex = e.NewPageIndex;
            LoadProductColor();
        }
        protected void gvProductColor_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                new ProductColorBL().Delete(new ProductColorDO { ProductColorID = Convert.ToInt32(gvProductColor.DataKeys[e.RowIndex].Value) });
            }
            catch
            {
                Functions.Alert("Có lỗi xảy ra!", Request.Url.ToString());
            }
            LoadProductColor();
            UpdatePanel2.Update();
        }
        ProductColorDO objProductColor = new ProductColorDO();
        protected void gvProductColor_SelectedIndexChanged(object sender, EventArgs e)
        {
            int ProductColorID = Convert.ToInt32(gvProductColor.DataKeys[gvProductColor.SelectedIndex].Value);
            Session["Action"] = 1;
            Session["ProductColorID"] = ProductColorID.ToString();
            objProductColor.ProductColorID = ProductColorID;
            objProductColor = new ProductColorBL().Select(objProductColor);
            txtColor.Text = objProductColor.Color.Replace("#", "");
            txtTabOrderID.Text = objProductColor.OrderID.ToString();

            if (!string.IsNullOrEmpty(objProductColor.Image))
            {
                hplColor.Visible = true;
                hplColor.NavigateUrl = "~/Media/" + objProductColor.Image;
            }
        }

        protected void gvProductColor_RowCommand(object sender, GridViewCommandEventArgs e)
        {
        }
        protected void btnTabSave_Click(object sender, EventArgs e)
        {
            // Theem moiw
            if (Session["Action"] == null)
            {

                objProductColor.Color = "#" + txtColor.Text.Trim().Replace("#", "");
                objProductColor.ProductID = int.Parse(Request.QueryString["ProductID"]);
                objProductColor.OrderID = int.Parse(txtTabOrderID.Text.Trim());
                if (!string.IsNullOrEmpty(fuColorImage.FileName))
                {
                    objProductColor.Image = UploadFileKM(fuColorImage);
                }

                new ProductColorBL().Insert(objProductColor);
                ClearForm();
                LoadProductColor();
                UpdatePanel2.Update();
            }
            //update
            else if (Session["Action"].ToString().Equals("1"))
            {
                if (Session["ProductColorID"] != null)
                    objProductColor.ProductColorID = int.Parse(Session["ProductColorID"].ToString());
                else objProductColor.ProductColorID = 0;
                objProductColor.Color = "#" + txtColor.Text.Trim().Replace("#", "");
                objProductColor.ProductID = int.Parse(Request.QueryString["ProductID"]);
                objProductColor.OrderID = int.Parse(txtTabOrderID.Text.Trim());
                if (!string.IsNullOrEmpty(fuColorImage.FileName))
                {
                    objProductColor.Image = UploadFileKM(fuColorImage);
                }

                new ProductColorBL().Update(objProductColor);
                Session["Action"] = null;
                Session["ProductColorID"] = null;
                LoadProductColor();
                ClearForm();
                UpdatePanel2.Update();
            }
        }

        protected void ClearForm()
        {
            txtColor.Text = "";
            txtTabOrderID.Text = "0";
        }

        protected void ddlProductLocation_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
        {
            if (lstX.Contains(e.Item.Value))
            {
                e.Item.Checked = true;
            }
        }
    }
}